<?php
include_once 'mysql.php';

$per = array_fill(1, 30, array_fill(1, 5, 0));
$pem = array_fill(1, 20, array_fill(1, 5, 0));
$gap_guru;
$gap_murid;
$avgTan;
$avgRel;
$avgRes;
$avgAss;
$avgEmp;
$avgTot;
$avmTan;
$avmRel;
$avmRes;
$avmAss;
$avmEmp;
$avmTot;
$sql = new mysqli('127.0.0.1',$username,$password,$database) or die(mysqli_error($sql));

$result_guru = $sql->query("SELECT nosoal as soal,jawaban,count(jawaban) as jumlah FROM $tabel_jawaban_guru group by soal,jawaban order by soal asc,jawaban asc;");
while($row = $result_guru->fetch_array()){
    $per[$row[0]][$row[1]] = $row[2];
}
$statistik_guru = $sql->query("SELECT nosoal as soal, avg(jawaban) as rata, std(jawaban) as deviasi FROM $tabel_jawaban_guru GROUP BY soal ORDER BY soal ASC;");
while($row = $statistik_guru->fetch_array()){
    $avg[$row[0]] = $row[1];
	$sdg[$row[0]] = $row[2];
}

$result_murid = $sql->query("SELECT nosoal as soal,jawaban,count(jawaban) as jumlah FROM $tabel_jawaban_murid group by soal,jawaban order by soal asc,jawaban asc;");
while($row = $result_murid->fetch_array()){
    $pem[$row[0]][$row[1]] = $row[2];
}
$statistik_murid = $sql->query("SELECT nosoal as soal, avg(jawaban) as rata, std(jawaban) as deviasi FROM $tabel_jawaban_murid GROUP BY soal ORDER BY soal ASC;");
while($row = $statistik_murid->fetch_array()){
    $avm[$row[0]] = $row[1];
	$sdm[$row[0]] = $row[2];
}
$sql->close();
for($i = 1; $i <= $jumlah_soal_guru / 2 ;$i++){
    $gap_guru[$i] = $avg[$i] - $avg[$i + $jumlah_soal_guru / 2];
}
for($i = 1; $i <= $jumlah_soal_murid / 2 ;$i++){
    $gap_murid[$i] = $avm[$i] - $avm[$i + $jumlah_soal_murid / 2];
}
$avgTan = ($gap_guru[1] + $gap_guru[2] + $gap_guru[3] + $gap_guru[4]) / 4;
$avgRel = ($gap_guru[5] + $gap_guru[6] + $gap_guru[7]) / 3;
$avgRes = ($gap_guru[8] + $gap_guru[9] + $gap_guru[10]) / 3;
$avgAss = ($gap_guru[11] + $gap_guru[12] + $gap_guru[13]) / 3;
$avgEmp = ($gap_guru[14] + $gap_guru[15]) / 2;
$avgTot = ($avgTan + $avgRel + $avgRes + $avgAss + $avgEmp) / 5;

$avmTan = ($gap_murid[1]);// + $gap_murid[2] + $gap_murid[3] + $gap_murid[4]) / 4;
$avmRel = ($gap_murid[2] + $gap_murid[3] + $gap_murid[4]) / 3;
$avmRes = ($gap_murid[5] + $gap_murid[6] + $gap_murid[7]) / 3;
$avmAss = ($gap_murid[8] + $gap_murid[9]) / 2;
$avmEmp = ($gap_murid[10]);
$avmTot = ($avmTan + $avmRel + $avmRes + $avmAss + $avmEmp) / 5;

?>